﻿using MediatR;
using T_vehicle.API.Application.Command.MaintenanceCommand;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.MaintenanceCommandHandlers
{
    public class PDelMaintenanceCommandHandlers:IRequestHandler<PDelMaintenanceCommand,int>
    {
        private readonly IMaintenanceRepository maintenanceRepository;

        public PDelMaintenanceCommandHandlers(IMaintenanceRepository maintenanceRepository)
        {
            this.maintenanceRepository = maintenanceRepository;
        }

        public async Task<int> Handle(PDelMaintenanceCommand request, CancellationToken cancellationToken)
        {
            var Id =  request.MaintenanceId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await maintenanceRepository.GetAsync(x=>Id.Contains(x.MaintenanceId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }

            return await maintenanceRepository.UpdateAsyncRange(list);
        }
    }
}
